package cn.schoolwow.quickdao.module.database.dml.instance.flow.update.service;

import cn.schoolwow.quickdao.domain.database.dml.UpdateType;
import cn.schoolwow.quickdao.module.database.dml.instance.flow.update.flow.SetUpdateInstanceParameterFlow;
import cn.schoolwow.quickdao.module.database.dml.instance.flow.update.flow.SetUpdateInstanceStatementFlow;
import cn.schoolwow.quickdao.module.database.dml.instance.flow.update.flow.updateType.SetPropertyListByIdFlow;
import cn.schoolwow.quickdao.module.database.dml.instance.flow.update.flow.updateType.SetPropertyListByUniqueFieldNameFlow;
import cn.schoolwow.quickdao.module.database.dml.instance.flow.update.flow.updateType.SetPropertyListByUniqueKeyFlow;
import cn.schoolwow.quickdao.module.database.parent.flow.executor.ExecuteUpdateConnectionFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class UpdateInstanceFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        UpdateType updateType = flowContext.checkInstanceData(UpdateType.class);

        switch (updateType){
            case UpdateByUniqueFieldName:{
                flowContext.executeFlowList(new SetPropertyListByUniqueFieldNameFlow());
                flowContext.putTemporaryData("name", "根据指定唯一字段列表更新实例");
            }break;
            case UpdateByUniqueKey:{
                flowContext.executeFlowList(new SetPropertyListByUniqueKeyFlow());
                flowContext.putTemporaryData("name", "根据唯一约束字段更新实例");
            }break;
            case UpdateById:{
                flowContext.executeFlowList(new SetPropertyListByIdFlow());
                flowContext.putTemporaryData("name", "根据Id更新实例");
            }break;
        }
        flowContext.executeFlowList(new SetUpdateInstanceStatementFlow(),
                new SetUpdateInstanceParameterFlow(),
                new ExecuteUpdateConnectionFlow());
    }

    @Override
    public String name() {
        return "更新实例";
    }

}
